package edu.wfmanage.models;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.util.DB;

public class HelpDeskUser  {
	
	private String username="";
	private  String password="";
	private int userid;
	private String emailid="";
	private String phone = "";
	
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public int getUserid() {
		return userid;
	}
	public void setUserid(int userid) {
		this.userid = userid;
	}
	public String getEmailid() {
		return emailid;
	}
	public void setEmailid(String emailid) {
		this.emailid = emailid;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	
	public static ArrayList<HelpDeskUser> findUserList(String rolename)	{
		
		ArrayList<HelpDeskUser> userList = new ArrayList<HelpDeskUser>();
		HelpDeskUser user = new HelpDeskUser();
		ResultSet result = null;
		Connection con = DB.getConnection();
		String query = "select * from user, role, user_role where user.user_id=user_role.user_id and user_role.role_id=role.role_id and role.role_name = '" + rolename + "';";
		result = DB.readFromDB(query, con);
		try{
			while(result.next()){
			  user.setUserid(result.getInt("user_id"));
			  user.setUsername(result.getString("user_name"));
			  user.setPassword(result.getString("password"));
			  user.setEmailid(result.getString("email_id"));
			  user.setPhone(result.getString("phone_no"));
			  userList.add(user);			  
			}
		}catch(SQLException ex){
			ex.printStackTrace();
		}
		
		return userList;
	}

}
